package treemap;

import hashmap.Student;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeMap;

public class Test1 {
    public static void main(String[] args) {
        TreeMap<Student,String> tm = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge() - o2.getAge();
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });

        tm.put(new Student("lisi", 24),"北京");
        tm.put(new Student("wangwu", 25),"上海");
        tm.put(new Student("zhaoliu", 26),"南京");

        Set<Student> students = tm.keySet();
        for (Student student : students) {
            System.out.println(student+tm.get(student));
        }
        System.out.println("--------------------------");
        tm.forEach((Student student,String s)->{
            System.out.println(student+s);
        });
    }
}
